package ly.sjun.design.prototype_pattern;

import ly.sjun.design.prototype_pattern.food.Apple;
import ly.sjun.design.prototype_pattern.food.Cookie;
import ly.sjun.design.prototype_pattern.food.Lemon;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: FoodCache
 * @Author: ly
 * @Date: 2023/2/3-9:33
 * @Description 食物缓存类
 **/
public class FoodCache {

    private static HashMap<String, Food> hashMap = new HashMap<>();

    public static void loadFoodData() {
        Apple apple = new Apple();
        Cookie cookie = new Cookie();
        Lemon lemon = new Lemon();

        apple.setId("apple");
        cookie.setId("cookie");
        lemon.setId("lemon");

        hashMap.put(apple.getId(), apple);
        hashMap.put(cookie.getId(), cookie);
        hashMap.put(lemon.getId(), lemon);
    }


    public static void show() {
        System.out.println("----------------------------");
        for (Map.Entry<String, Food> foodEntry : hashMap.entrySet()) {
            System.out.println(foodEntry.getKey());
            System.out.println(foodEntry.getValue().show());
        }
    }

    public static Food getFood(String id) {
        return (Food) hashMap.get(id).clone();
    }

}
